<template>
	<view>
		<view class="bg" />
		<view class="content">
			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" :style-type="styleType"
					:active-color="activeColor" @clickItem="onClickItem" style="width: 160px;" />
			</view>
			<view style="float: none;position: relative;left: 312px;display: flex;align-items: center;top:-20px"
				@click="selectDate()">
				<image src="../../../resource/index/jytj/yygh.png"
					style="width: 12px; height: 12px; margin-right: 3px;"></image>
				自定义
			</view>
			<view style="height: 4px;background-color: #e3e3e366;margin-bottom: 12px;"></view>
			<view class="content1">
				<view v-if="current === 0">
					<view style="display: flex; justify-content: space-around; width: 300px;">
						<view
							style="width: 120px;height: 134px;box-shadow: 1px 1px 4px 0px #e3e3e3;border-radius: 15px;display: flex;flex-direction: column;align-items: center;padding: 24px 0;box-sizing: border-box;">
							<view
								style="width: 36px;height: 36px;background: linear-gradient(to bottom right, #FFB35C, #FF8941);border-radius: 10px;padding: 8px 0; box-sizing: border-box;margin-bottom: 12px;">
								<image src="../../../resource/index/jytj/shouru.png" style="width: 20px;height: 20px;">
								</image>
							</view>
							<span style="margin-bottom: 4px;font-size: 16px;">￥2066.56</span>
							<span style="margin-bottom: 4px;">收入</span>
						</view>
						<view
							style="width: 120px;height: 134px;box-shadow: 1px 1px 4px 0px #e3e3e3;border-radius: 15px;display: flex;flex-direction: column;align-items: center;padding: 24px 0;box-sizing: border-box;">
							<view
								style="width: 36px;height: 36px;background: linear-gradient(to bottom right, #7DB3FF, #4886FF);border-radius: 10px;padding: 8px 0; box-sizing: border-box;margin-bottom: 12px;">
								<image src="../../../resource/index/jytj/dingdan.png" style="width: 20px;height: 20px;">
								</image>
							</view>
							<span style="margin-bottom: 4px;font-size: 16px;">53</span>
							<span style="margin-bottom: 4px;">订单量</span>
						</view>
					</view>
				</view>
				<view v-if="current === 1">
					<view style="display: flex; justify-content: space-around; width: 300px;">
						<view
							style="width: 120px;height: 134px;box-shadow: 1px 1px 4px 0px #e3e3e3;border-radius: 15px;display: flex;flex-direction: column;align-items: center;padding: 24px 0;box-sizing: border-box;">
							<view
								style="width: 36px;height: 36px;background: linear-gradient(to bottom right, #FFB35C, #FF8941);border-radius: 10px;padding: 8px 0; box-sizing: border-box;margin-bottom: 12px;">
								<image src="../../../resource/index/jytj/shouru.png" style="width: 20px;height: 20px;">
								</image>
							</view>
							<span style="margin-bottom: 4px;font-size: 16px;">￥5210.33</span>
							<span style="margin-bottom: 4px;">收入</span>
						</view>
						<view
							style="width: 120px;height: 134px;box-shadow: 1px 1px 4px 0px #e3e3e3;border-radius: 15px;display: flex;flex-direction: column;align-items: center;padding: 24px 0;box-sizing: border-box;">
							<view
								style="width: 36px;height: 36px;background: linear-gradient(to bottom right, #7DB3FF, #4886FF);border-radius: 10px;padding: 8px 0; box-sizing: border-box;margin-bottom: 12px;">
								<image src="../../../resource/index/jytj/dingdan.png" style="width: 20px;height: 20px;">
								</image>
							</view>
							<span style="margin-bottom: 4px;font-size: 16px;">103</span>
							<span style="margin-bottom: 4px;">订单量</span>
						</view>
					</view>
				</view>
			</view>
			</uni-section>
		</view>
		<view class="content" style="margin-top: 12px;">
			<view v-if="current === 0">
				<span style="font-size: 16px;">收入分布</span>
				<view style="height: 4px;background-color: #e3e3e366;margin-bottom: 12px;margin-top: 6px;"></view>
				<view class="charts-box">
					<qiun-data-charts type="ring" :opts="opts" :chartData="chartData" />
				</view>
			</view>

			<view v-if="current === 1">
				<span style="font-size: 16px;">收入分布</span>
				<view style="height: 4px;background-color: #e3e3e366;margin-bottom: 12px;margin-top: 6px;"></view>
				<view class="charts-box">
					<qiun-data-charts type="ring" :opts="opts" :chartData="chartData" />
				</view>
			</view>
		</view>

		<view class="content" style="margin-top: 12px;">
			<view v-if="current === 0">
				<span style="font-size: 16px;">订单分布</span>
				<view style="height: 4px;background-color: #e3e3e366;margin-bottom: 12px;margin-top: 6px;"></view>
				<view class="charts-box">
					<qiun-data-charts type="column" :opts="opts1" :chartData="chartData1" />
				</view>
			</view>

			<view v-if="current === 1">
				<span style="font-size: 16px;">订单分布</span>
				<view style="height: 4px;background-color: #e3e3e366;margin-bottom: 12px;margin-top: 6px;"></view>
				<view class="charts-box">
					<qiun-data-charts type="column" :opts="opts1" :chartData="chartData1" />
				</view>
			</view>
		</view>

		<view class="dateShow" v-if="isVisible">
			<span>一周内</span>
			<span>一个月内</span>
			<span>三个月内</span>
			<span>半年内</span>
			<span>一年内</span>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				chartData1: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['column'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts1: {
					color: ["#FAC858", "#EE6666", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 15, 0, 5],
					enableScroll: false,
					legend: {},
					xAxis: {
						disableGrid: true
					},
					yAxis: {
						data: [{
							min: 0
						}]
					},
					extra: {
						column: {
							type: "group",
							width: 30,
							activeBgColor: "#000000",
							activeBgOpacity: 0.08,
							linearType: "custom",
							seriesGap: 5,
							linearOpacity: 0.5,
							barBorderCircle: true,
							customColor: [
								"#FA7D8D",
								"#EB88E2"
							]
						}
					}
				},
				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['ring'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					rotate: false,
					rotateLock: false,
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [5, 5, 5, 5],
					dataLabel: true,
					enableScroll: false,
					legend: {
						show: true,
						position: "right",
						lineHeight: 25
					},
					title: {
						name: "",
					},
					subtitle: {
						name: "",
					},
					extra: {
						ring: {
							ringWidth: 60,
							activeOpacity: 0.5,
							activeRadius: 10,
							offsetAngle: 0,
							labelWidth: 15,
							border: false,
							borderWidth: 3,
							borderColor: "#FFFFFF"
						}
					}
				},
				isVisible: false,
				items: ['今日', '昨日'],
				styles: [{
						value: 'button',
						text: '按钮',
						checked: true
					},
					{
						value: 'text',
						text: '文字'
					}
				],
				colors: ['#007aff'],
				current: 0,
				colorIndex: 0,
				activeColor: '#007aff',
				styleType: 'button'
			}
		},
		onReady() {
			this.getServerData();
			this.getServerData1();
		},
		methods: {
			getServerData1() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						categories: ["维修", "保养", "洗车"],
						series: [{
								name: "目标值",
								data: [235, 336, 231]
							},
						]
					};
					this.chartData1 = JSON.parse(JSON.stringify(res));
				}, 500);
			},
			getServerData() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						series: [{
							data: [{
								"name": "保养",
								"value": 64
							}, {
								"name": "洗车",
								"value": 24
							},{
								"name": "维修",
								"value": 12
							}]
						}]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
			},
			styleChange(e) {
				if (this.styleType !== e.detail.value) {
					this.styleType = e.detail.value
				}
			},
			colorChange(e) {
				if (this.styleType !== e.detail.value) {
					console.log(e.detail.value);
					this.activeColor = e.detail.value
				}
			},
			selectDate() {
				this.isVisible = !this.isVisible
			}
		}
	}
</script>

<style lang="scss" scoped>
	  .charts-box {
	    width: 100%;
	    height: 300px;
	  }
	.bg {
		width: 100%;
		background-color: #3183FB;
		height: 172px;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		padding: 0;
	}

	.uni-padding-wrap {
		// width: 750rpx;
		padding: 0px 30px;
		box-sizing: border-box;
		display: flex;
		justify-content: center;
	}

	.content {
		position: relative;
		top: -152px;
		left: 22.5rpx;
		border-radius: 20px;
		width: 94%;
		background-color: white;
		padding: 28px 16px;
		box-sizing: border-box;
	}

	.content1 {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
		height: 150px;
		text-align: center;
	}

	.content-text {
		font-size: 14px;
		color: #666;
	}

	.color-tag {
		width: 25px;
		height: 25px;
	}

	.uni-list {
		flex: 1;
	}

	.uni-list-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex: 1;
		flex-direction: row;
		background-color: #FFFFFF;
	}


	.uni-list-item__container {
		padding: 12px 15px;
		width: 100%;
		flex: 1;
		position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		box-sizing: border-box;
		/* #endif */
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		border-bottom-style: solid;
		border-bottom-width: 1px;
		border-bottom-color: #eee;
	}

	.uni-list-item__content-title {
		font-size: 14px;
	}

	.dateShow {
		float: none;
		position: relative;
		width: 100px;
		height: 160px;
		background-color: white;
		top: -1186px;
		left: 300px;
		border-radius: 10px;
		box-shadow: 1px 1px 4px 0px #e3e3e3;
		padding: 4px 4px;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		align-items: center;
		z-index: 5;
	}

	.dateShow span {
		margin: 4px 0;
		font-size: 12px;
	}
</style>